package com.selenium.webdriver;

import java.util.List;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.Select;

public class FindAFlightPage {
	
	@FindBy(name = "tripType")
	List <WebElement> tripType;
	
	@FindBy(name = "passCount")
	WebElement numberOfPassengers;
	
	@FindBy(name = "fromPort")
	WebElement departingFrom;
	
	@FindBy(name = "fromMonth")
	WebElement monthOfDepart;
	
	@FindBy(name = "fromDay")
	WebElement dayOfDepart;
	
	@FindBy(name = "toPort")
	WebElement arriveIn;
	
	@FindBy(name = "toMonth")
	WebElement monthOfReturn;
	
	@FindBy(name = "toDay")
	WebElement dayOfReturn;
	
	@FindBy(name = "servClass")
	List <WebElement> serviceClass;
	
	@FindBy(name = "airline")
	WebElement airlinePreferred;
	
	@FindBy (name = "findFlights")
	WebElement findFlightsButton;
	
	//Assign values as selection
	public void assignValuesAsSelection (String[] selectionsOfFlights)
	{
		//Select radio button of trip type
		switch (selectionsOfFlights[0].charAt(0)) 
		{
	    case 'r':
	    	tripType.get(0).click();
	        break;
	    case 'o':
	    	tripType.get(1).click();
	        break;
		}
		Select numberofpassengers = new Select (numberOfPassengers);
		numberofpassengers.selectByValue(selectionsOfFlights[1]);
		
		Select departingfrom = new Select (departingFrom);
		departingfrom.selectByValue(selectionsOfFlights[2]);
		
		Select monthofdepart = new Select (monthOfDepart);
		monthofdepart.selectByValue(selectionsOfFlights[3]);
		
		Select dayofdepart = new Select (dayOfDepart);
		dayofdepart.selectByValue(selectionsOfFlights[4]);
		
		Select arrivein = new Select (arriveIn);
		arrivein.selectByValue(selectionsOfFlights[5]);
		
		Select monthofreturn = new Select (monthOfReturn);
		monthofreturn.selectByValue(selectionsOfFlights[6]);
		
		Select dayofreturn = new Select (dayOfReturn);
		dayofreturn.selectByValue(selectionsOfFlights[7]);
		//Select radio button for service class
		switch (selectionsOfFlights[8].charAt(0)) 
		{
	    case 'E':
	    	serviceClass.get(0).click();
	        break;
	    case 'B':
	    	serviceClass.get(1).click();
	        break;
	    case 'F':
	    	serviceClass.get(2).click();
	        break;
		}
		
		Select airlinepreferred = new Select (airlinePreferred);
		airlinepreferred.selectByVisibleText(selectionsOfFlights[9]);
	}
	//Click on continue button
	public void clickContinueButton()
	{
		findFlightsButton.click();
	}

}
